<?php

class Application_Plugin_Adminaccess_Plugin extends Nimblecms_Controller_Plugin {
	
	public function __construct() {
		parent::__construct();
	}
	
	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		$requestUri = $request->getRequestUri();
		
		if($requestUri == null || $requestUri == '') {
			return;
		}
		
		$requestUri = rtrim(ltrim($requestUri, '/'), '/');
		
		$requestUri = '/' . $requestUri;
		
		$ips = $this->getParam('ips');
		
		if(substr($requestUri, 0, 7) != '/admin/' || $ips == null || $ips == '') {
			return;
		}
		
		$ips = explode(',', $ips);
		
		$ip = $request->getClientIp();
		
		if(in_array($ip, $ips)) {
			$request->setModuleName('default')
					->setControllerName('auth')
					->setActionName('deny')
					->setDispatched(TRUE);
		}
	}
}

?>